/**
 * Created by lt on 2017/6/5.
 */
/*编辑*/
function member_edit(title, url, id, w, h) {
    layer_show(title, url, w, h);
}

/*编辑*/
function picture_edit(title, url, id) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

/*不推荐*/
function productEntity_stop(productId, productEntityId) {
    layer.confirm('确认要取消推荐吗？', function (index) {
        $.ajax({
            cache: true,
            type: 'POST',
            data: $('#form-member-add').serialize(),
            url: '/productEntity/getProductEntitySubmit?specialRecommendation=0&productId=' + productId + '&productEntityId=' + productEntityId,
            async: false,
            success: function (data) {
                layer.msg('已取消推荐!', {icon: 5, time: 1000});
                window.location.reload();
            }
        })
    });
}
/*修改产品实体状态*/
function modifyProductEntityStatus(productEntityId, status) {
    var postData = {productEntityId: productEntityId, status: status}
    $.ajax({
        cache: true,
        type: 'POST',
        data: postData,
        url: '/admin/productEntity/modifiyProductEntity.html',
        async: false,
        success: function (data) {
            if (data.code != 1) {
                layer.msg(data.msg, {icon: 5, time: 1000});
            }
            layer.msg('已取消推荐!', {icon: 5, time: 1000});
            window.location.reload();
        }
    })

}

/*特别推荐*/
function productEntity_start(productId, productEntityId) {
    layer.confirm('确认要特别推荐吗？', function (index) {
        $.ajax({
            cache: true,
            type: 'POST',
            data: $('#form-member-add').serialize(),
            url: '/productEntity/getProductEntitySubmit?specialRecommendation=1&productId=' + productId + '&productEntityId=' + productEntityId,
            async: false,
            success: function (data) {
                layer.msg('已特别推荐!', {icon: 6, time: 1000});
                window.location.reload();
            }
        })
    });
}

/*产品-序列号*/
function makeProductEntitySerial(productEntityId) {
    var divhtml = '<div align="center" id="sellerList">';
    divhtml += '<span class="select-box">';
    divhtml += '  <input type="hidden"  id="productEntityId">';
    divhtml += ' <input type="text" id="serialNumber"  placeholder=" 请输入生成序列号产品数量" style="width:300px" class="input-text">';
    divhtml += '</span>';
    divhtml += '<div align="center"><button id="serialSubmit"  class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 确定</button></div>';
    divhtml += '</div>';

    layer.open({
        type: 1,
        area: ['350px', '150px'],
        shade: false,
        title: false,
        skin: 'yourclass',
        content: divhtml
    });
    $("#serialSubmit").unbind();
    $("#serialSubmit").bind("click", function () {
        var postData = {"productEntityId": productEntityId, "serialNumber": $("#serialNumber").val()};
        $.ajax({
            cache: true,
            type: 'POST',
            data: postData,
            url: '/admin/productEntity/makeProductEntitySerial.html',
            async: false,
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    layer.msg(data.msg, {icon: 5, time: 1000});
                    console.log(data.msg);
                    return;
                }
                layer.msg('操作成功!', {icon: 6, time: 1000}, function () {
                    location.reload();
                })
            }
        })
    });
}

function makeSerialBarCode(productEntityId) {

    window.location.href = '/admin/productEntity/getBarcode.html?productEntityId=' + productEntityId;
}

//打印
$("#doPrint").bind("click", function () {
    var newstr = "";
    newstr = window.document.getElementById('serialBarCodeDiv').innerHTML;
    window.document.write('<html><head></head><body>' + newstr + '</body></html>');
    window.document.close();
    window.print();

});

